package com.kukudexin.safety;

/**
 * @author: 酷酷的鑫
 * @description:
 */
public class ThreadCount implements Runnable {
    private static int count = 100;
    private Object objectLock = new Object();
    @Override
    public void run() {
        while (true) {
            try {
                //运行状态----休眠状态--cpu的执行权让给其他的线程
                // 休眠----运行状态
                Thread.sleep(30);
            } catch (Exception e) {

            }
            cal();
        }
    }

    private static void cal() {
        synchronized (ThreadCount.class) {
            if (count > 1) {
                count--;
                System.out.println(Thread.currentThread().getName() + "," + count);
            }
        }
    }

    public static void main(String[] args) {
        ThreadCount threadCount1 = new ThreadCount();
        new Thread(threadCount1).start();
        new Thread(threadCount1).start();
    }
}
